package com.lijiajia.cloud.authserver.security;

import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
import org.springframework.security.oauth2.core.user.OAuth2User;

import java.util.Map;

/**
 * oauth2 登陆方式用户信息
 *
 * @author lijiajia
 * @since 2019-05-21
 */
public class OAuthUser extends BaseUser implements OAuth2User {
    private final Map<String, Object> attributes;
    private final OidcUserInfo userInfo;

    public OAuthUser(BaseUser user, Map<String, Object> attributes, OidcUserInfo userInfo) {
        super();
        this.userInfo = userInfo;
        super.userId = user.userId;
        super.loginName = user.loginName;
        super.password = user.password;
        super.email = user.email;
        super.telephone = user.telephone;
        super.avatar = user.avatar;
        super.realName = user.realName;
        super.enabled = user.enabled;
        super.deleted = user.deleted;
        super.joinTime = user.joinTime;
        super.authorities = user.authorities;
        this.attributes = attributes;
    }

    @Override
    public Map<String, Object> getAttributes() {
        return attributes;
    }

    @Override
    public String getName() {
        return super.getUserId();
    }

    public OidcUserInfo getUserInfo() {
        return userInfo;
    }
}
